'''###########################################################################################################################
### File: objects.py
### Name: Patrick Delaney, Andrew Oberlin
### Class: CSE 487
### Instructor: Dr.Zmuda
### Assignment: Final Project
### Description: Class for saving and loading the objects
################
'''
import cPickle as serialize

class Object:
	'''
	### Name: __init__ (Constructor)
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Initializes the main character object
	'''
	def __init__(self):
		self.mainTexture = ""
		self.name = ""
		self.isPlatform = 0
		
	'''
	### Name: setName
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Sets the name for this character
	'''
	def setName(self, name):
		self.name = name.capitalize()
		
	'''
	### Name: setIsPlatform
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Sets the isPlatform for this character
	'''
	def setIsPlatform(self, isPlatform):
		self.isPlatform = isPlatform
		
	'''
	### Name: setMainTexture
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Sets the main texture for this character
	###				 when the character idles he will return
	###				 to this texture
	'''
	def setMainTexture(self, texture):
		self.mainTexture = texture
		
	'''
	### Name: getMainTexture
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Gets the main texture for this character
	###				 when the character idles he will return
	###				 to this texture
	'''
	def getMainTexture(self):
		return self.mainTexture
		
	'''
	### Name: getName
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Gets the name for this character
	'''
	def getName(self):
		return self.name
	
	'''
	### Name: getIsPlatform
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Gets the isPlatform for this character
	'''
	def getIsPlatform(self):
		return self.isPlatform
	
	'''
	### Name: save
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Saves this character as a serialized file
	###				 with name 'projects/<projectName>/characters/main/<name>.char' 
	###				 **name attribute required**
	'''
	def save(self, projectName):
		if (self.name):
			file = open( "projects/" + projectName + "/objects/" + self.name +  ".item", "wb" )
			serialize.dump(self, file, 1)
			
	'''
	### Name: load
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Loads the character from a serialized file
	###				 with name 'projects/<projectName>/characters/main/<name>.char'
	'''
	def load(self, path):
		try:
			file = open( path, "r" )
			newSelf = serialize.load(file)
			self.copy(newSelf)
		except IOError, e:
			print "Problem loading the object"
			print e
			
	'''
	### Name: copy
	### Author: Andrew Oberlin, Patrick Delaney
	### Parameters: None
	### Description: Copies the newSelf's attributes to self
	'''
	def copy(self, newSelf):
		self.mainTexture = newSelf.mainTexture
		print self.mainTexture
		self.name = newSelf.name
		self.isPlatform = newSelf.isPlatform
	
	def __str__(self):
		return "Object: " + self.name + " with texture file: " + self.mainTexture
		